package com.example.mangodb.Serives.impl;

import com.example.mangodb.Serives.IUserService;
import com.example.mangodb.domain.User;
import com.example.mangodb.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 普发忠
 * @Date: 2021/09/18/11:56
 */
@Service
public class IUserServiceimpl implements IUserService {
    @Autowired
    private UserRepository userRepository;
    
    
    @Override
    public void save(User user) {
        userRepository.save(user);
    }
    
    @Override
    public void update(User user) {
        userRepository.save(user);
    }
    
    @Override
    public void delete(String id) {
        userRepository.deleteById(id);
    }
    
    @Override
    public User getUser(String id) {
        return userRepository.findById(id).get();
    }
    
    @Override
    public List<User> getUsers() {
        return userRepository.findAll();
    }
    
    @Override
    public User findByName(String name) {
        return userRepository.findByName(name);
    }
    
    @Override
    public User findByNameAndAge(String name, int age) {
        return userRepository.findByNameAndAge(name, age);
    }
    
    @Override
    public User findByIdAndName(String id, String age) {
        return userRepository.findByIdAndName(id, age);
    }
}
